package cn.funnyxb.powerremember.uis.task.taskEdit.alarm;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import cn.funnyxb.powerremember.beans.AlarmInfo;
import cn.funnyxb.powerremember.db.AllTableHolders;
import cn.funnyxb.powerremember.db.tables.Tbholder_alarmsinfo;
import cn.funnyxb.tools.appFrame.App;
import cn.funnyxb.tools.appFrame.debugTool.Debuger;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;

public class AlarmHelper
{
  private Context context;

  public AlarmHelper(Context paramContext)
  {
    this.context = paramContext;
  }

  private void log(String paramString)
  {
    Debuger.log("alarmhelper", paramString);
  }

  private void unRegAlarm(int paramInt)
  {
    Intent localIntent = new Intent(this.context, AlarmReceiver.class);
    PendingIntent localPendingIntent = PendingIntent.getBroadcast(this.context, paramInt, localIntent, 0);
    ((AlarmManager)this.context.getSystemService("alarm")).cancel(localPendingIntent);
  }

  public void delAlarmsFromTbByTaskid(int paramInt)
  {
    log("dlealarmsfromtb, taskid=" + paramInt);
    App.getApp().getAllTableHolders().getTbholder_alarmsinfo().delByTaskId(paramInt);
  }

  public void insertAlarms2TbAndReg2System(int paramInt, ArrayList<AlarmInfo> paramArrayList)
  {
    log("insert and reg,cnt=" + paramArrayList.size() + ",taskId=" + paramInt + ", allalarms=" + paramArrayList);
    if ((paramInt < 0) || (paramArrayList == null))
      label49: return;
    int i = 1;
    Iterator localIterator1 = paramArrayList.iterator();
    Iterator localIterator2;
    if (!(localIterator1.hasNext()))
    {
      log("insert2Table complete");
      localIterator2 = App.getApp().getAllTableHolders().getTbholder_alarmsinfo().queryByTaskId(paramInt).iterator();
    }
    int l;
    for (int k = 1; ; k = l)
    {
      if (!(localIterator2.hasNext()))
      {
        log("regalarm completed");
        break label49:
        AlarmInfo localAlarmInfo1 = (AlarmInfo)localIterator1.next();
        StringBuilder localStringBuilder1 = new StringBuilder("insert 2 table alarm: ");
        int j = i + 1;
        log(i + "time=" + localAlarmInfo1.getTime_hh() + ":" + localAlarmInfo1.getTime_mm());
        App.getApp().getAllTableHolders().getTbholder_alarmsinfo().insertARecord(paramInt, localAlarmInfo1);
        i = j;
      }
      AlarmInfo localAlarmInfo2 = (AlarmInfo)localIterator2.next();
      StringBuilder localStringBuilder2 = new StringBuilder("reg2sys table alarm: ");
      l = k + 1;
      log(k + "time=" + localAlarmInfo2.getTime_hh() + ":" + localAlarmInfo2.getTime_mm());
      if (!(localAlarmInfo2.isEnabled()))
        continue;
      regAlarm(localAlarmInfo2);
    }
  }

  public void regAlarm(AlarmInfo paramAlarmInfo)
  {
    log("reg alarm,time=" + paramAlarmInfo.getTime_hh() + ":" + paramAlarmInfo.getTime_mm());
    Calendar localCalendar = Calendar.getInstance();
    localCalendar.setTimeInMillis(System.currentTimeMillis());
    int i = paramAlarmInfo.getTime_hh();
    int j = paramAlarmInfo.getTime_mm();
    localCalendar.set(11, i);
    localCalendar.set(12, j);
    localCalendar.set(13, 0);
    localCalendar.set(14, 0);
    if (localCalendar.getTimeInMillis() < System.currentTimeMillis())
      localCalendar.add(10, 24);
    Intent localIntent = new Intent(this.context, AlarmReceiver.class);
    localIntent.putExtra("alarminfo", paramAlarmInfo);
    PendingIntent localPendingIntent = PendingIntent.getBroadcast(this.context, paramAlarmInfo.get_id(), localIntent, 0);
    ((AlarmManager)this.context.getSystemService("alarm")).setRepeating(0, localCalendar.getTimeInMillis(), 86400000L, localPendingIntent);
  }

  public void unRegAlarmsByTaskid(int paramInt)
  {
    log("unreg ,taskid=" + paramInt);
    ArrayList localArrayList = App.getApp().getAllTableHolders().getTbholder_alarmsinfo().queryByTaskId(paramInt);
    if ((localArrayList == null) || (localArrayList.size() == 0))
      return;
    Iterator localIterator = localArrayList.iterator();
    while (true)
    {
      if (localIterator.hasNext());
      unRegAlarm(((AlarmInfo)localIterator.next()).get_id());
    }
  }
}

/* Location:           E:\Desktop\复件 classes_dex2jar.jar
 * Qualified Name:     cn.funnyxb.powerremember.uis.task.taskEdit.alarm.AlarmHelper
 * JD-Core Version:    0.5.3
 */